package task3;

import java.util.Collection;
import java.util.LinkedList;

public class CyclicBuffer<E> extends LinkedList<E> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4134599162057405079L;

	private int MAX_SIZE;

	public CyclicBuffer() {
		this(10);
	}

	public CyclicBuffer(int max_size) {
		super();
		MAX_SIZE = max_size;
	}

	public CyclicBuffer(Collection<? extends E> c) {
		super(c);
		MAX_SIZE = c.size();
	}

	public boolean isFull() {
		return (size() == MAX_SIZE);
	}

	public synchronized boolean put(final E e) {
		if (isFull()) {
			return false;
		}

		addLast(e);
		return true;
	}

	public synchronized E retrieve() {
		if (isEmpty()) {
			return null;
		}

		return removeLast();
	}

	public synchronized String retrieveString() {
		if (isEmpty()) {
			return "";
		}

		return (String) removeLast();
	}
}
